/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Form = require("form");
	
    var instance = {
        initComponent: function (params,widget) {
        	var grid = new Grid({
        		parentNode: ".J-grid",
        		//autoRender: false,
        		model: {
        			url: "api/travelcontractrefund/queryrefund",
        			params: function(){
        				var subnav = widget.get("subnav");
        				return {
        					 "status": subnav.getValue("status"),
        				     "refundDate": subnav.getValue("startDate").start,
        				     "refundDateEnd": subnav.getValue("startDate").end,
        				     fetchProperties: widget.constant.fetchProperties
        				}
        			},
        			columns: [{
        				name: "travelContractRefund.travelContract.memberCertificates",
        				label: "会员证号码",
        				format: "detail",
        				formatparams: {
        					key: "detail",
        					handler: function(index,data,rowEle){
        						var form = widget.get("form");
        						var memberCertificates = data.travelContractRefund.travelContract.memberCertificates;
								if(memberCertificates){
									form.setValue("memberCertificates",data.travelContractRefund.travelContract.memberCertificates);
									form.setValue("pkReturnCredentials",data.returnCredentials.pkReturnCredentials);
									form.setValue("defaultRatio",data.returnCredentials.defaultRatio);
								    form.setValue("flatCost",data.returnCredentials.flatCost);
									form.setValue("cause",data.returnCredentials.cause);
									form.setValue("price",data.returnCredentials.price);
									form.setValue("version",data.returnCredentials.version);
									widget.handler.form.searchContact(widget,memberCertificates,data.returnCredentials.pkReturnCredentials);
								}
        					}
        				}
        			},{
        				name: "travelContractRefund.travelContract.contactNo",
        				label: "合同号",
        			},{
        				name: "travelContractRefund.travelContract.member.personalInfo.name",
        				label: "会员",
        			},{
        				name: "travelContractRefund.travelContract.member.personalInfo.idNumber",
        				label: "证件号",
        			},{
        				name: "travelContractRefund.travelContract.productRule.product.name",
        				label: "产品",
        			},{
        				name: "travelContractRefund.travelContract.productType.name",
        				label: "产品类型",
        			},{
        				name: "travelContractRefund.travelContract.number",
        				label: "份数",
        			},{
        				name: "returnCredentials.operateDate",
        				label: "申请日期",
        				format: "date"
        			},{
        				name: "returnCredentials.price",
        				label: "应退金额(元)",
        			},{
        				name: "travelContractRefund.status.value",
        				label: "状态",
        			},{
        				name: "operate",
        				label: "操作",
        				format: "button",
        				formatparams: [{
        					id: "chargeback",
        					text: "退费",
        					show: function(value,data){
        						if(data.travelContractRefund.status.key == "NoRefund"){
        							return true;
        						}else{
        							return false;
        						}
        					},
        					handler:function(index,data,rowEle){
        							widget.handler.chargeBackClick(data,widget);
        					}
        				},{
        					id: "check",
        					text: "查看",
        					show: function(value,data){
        						if(data.travelContractRefund.status.key == "Refund"){
        							return true;
        						}else{
        							return false;
        						}
        					},
        					handler:function(index,data,rowEle){
        							widget.handler.checkClick(data,widget);
        							$(".J-dialog-confirm").hide();
        						}
        				}]
        			}]
        		}
        	});
        	widget.set("grid",grid)
        }
    };
    module.exports = instance;
});
